package cn.lliiooll.ippzonetoolbox.ui.activities.launcher;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;
import cn.lliiooll.ippzonetoolbox.R;
import cn.lliiooll.ippzonetoolbox.task.PTask;
import cn.lliiooll.ippzonetoolbox.task.PTaskBuilder;
import cn.lliiooll.ippzonetoolbox.utils.ActivitiesManager;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import lombok.Getter;

@Route(path = "/ipp/launcher")
public class LauncherActivity extends AppCompatActivity {

    @Getter
    public static LauncherActivity instance;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        instance = this;
        ARouter.init(getApplication());
        setContentView(R.layout.activity_launcher);
        ActivitiesManager.add(this);
        final Button pass = findViewById(R.id.launcher_button_pass);
        pass.setBackgroundResource(R.drawable.ic_launcher_pass_24dp);
        pass.setAlpha(100);
        final PTask pt = PTaskBuilder.builder()
                .setLabel("launcher")
                .setRunnable(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 3; i > 0; i--) {
                            final int finalI = i;
                            LauncherActivity.getInstance().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    pass.setText("跳过 " + finalI);
                                }
                            });
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                            }
                        }
                    }
                })
                .onFinished(new Runnable() {
                    @Override
                    public void run() {
                        ARouter.getInstance().build("/ipp/main").navigation();
                    }
                });
        pt.start();
        pass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance().build("/ipp/main").navigation();
                PTaskBuilder.remove("launcher").cancel();
            }
        });
    }
}
